package com.study.demoservice.config;

import com.study.demoservice.bean.Student;
import com.study.demoservice.controller.StudentController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * 可以通过几种方式来决定 Bean 的注入顺序，在 {@link StudentController#listStudents()} 可以看到 Bean 的顺序
 * 1、方法的顺序
 * 2、@Order 的优先级
 * 3、@DependsOn
 *
 */
@Configuration
public class BeanConfig {

    @Bean
    @Order(2)
    public Student student2() {
        return createStudent("2", "李四");
    }

    @Bean
    @Order(1)
    public Student student1() {
        return createStudent("1", "张三");
    }

    private Student createStudent(String id, String name) {
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        return student;
    }

    //@Bean
    public String serviceName() {
        return "Service Name";
    }

}
